home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cenvid9.zip / PATHADD.BAT < prev    next >
DOS Batch File  |  1994-03-04  |  1KB  |  49 lines

  1. @echo off
  2. REM *********************************************************
  3. REM *** PathAdd.bat - add a directory to the current path ***
  4. REM *** ver.1         if it's not already there.          ***
  5. REM *********************************************************
  6.  
  7. if "%1"=="" GOTO SHOW_HOW
  8. if not "%2"=="" GOTO SHOW_HOW
  9. cenvi %0.BAT %1
  10. GOTO FINI
  11.  
  12. :SHOW_HOW
  13. ECHO PathAdd.bat - Add a directory to the PATH if it's not already there
  14. ECHO USAGE: PathBat DirSpec
  15. GOTO FINI
  16.  
  17.  
  18. GOTO CENVI_EXIT
  19.  
  20. main(argc,argv)
  21. {
  22.    NewDir = argv[1]
  23.    if ( AlreadyInPath(NewDir) ) {
  24.       printf("The Directory \"%s\" is already in PATH.\n",NewDir)
  25.    } else {
  26.       // File is not already in the path, and so append to the end of PATH.
  27.       // If there isn't a semi-colon at the end of PATH already, then add one.
  28.       if ( PATH[strlen(PATH)-1] != ';' )
  29.          strcat(PATH,";")
  30.       // Append this new directory to the end of the path statement
  31.       strcat(PATH,NewDir)
  32.    }
  33. }
  34.  
  35. AlreadyInPath(Dir) // search through path for this Dir, return True if found, else False
  36. {
  37.    len = strlen(Dir)
  38.    p = PATH
  39.    do {
  40.       if ( 0 == strnicmp(p,Dir,len)  && (p[len]==0 || p[len]==';') )
  41.          return(True)
  42.       p = strchr(p,';')
  43.    } while( p++ != NULL )
  44.    return(False)
  45. }
  46.  
  47. :CENVI_EXIT
  48. :FINI
  49.